<?php
/**
 * Description:
 *
 * @author      Eden
 * @datetime    2017/1/11 00:00
 * @copyright   WuHan HuQi Technology Co.,Ltd.
 * @url         http://cnhuqi.com
 */

class Delete_Model extends API_Model
{
    /**
     * 初始化
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * 主程序
     * @param $params
     */
    public function run($params)
    {
        $send['state'] = false;
        do {

            if ($this->input->method(true) !== 'POST') {
                $send['error'] = '非法请求';
                break;
            }

            if (empty($params['userId'])) {
                $send['error'] = '参数错误';
                break;
            }

            if (empty($params['goodsId'])) {
                $send['error'] = '请选择商品';
                break;
            }

            $db = clone($this->db);
            $db->where(['userId' => $params['userId'], 'goodsId' => $params['goodsId']]);
            $db->delete('user_car');
            if ($db->affected_rows()) {
                $send['state'] = true;
                $send['data'] = [
                    'msg' => '删除成功'
                ];
            } else {
                $send['error'] = '删除失败';
            }
        } while(false);
        $this->output->send($send);
    }

}
